import http from "@/api";
import { instrumentListType } from "@/views/instrumentList/type";
import { joinQueryParams } from "@/utils/qs";

// 查询响应类型
interface selectResType {
  list: instrumentListType;
  total: number;
}

// 添加/编辑/删除响应类型
// interface addEditDeleteResType {
//   data?: Object;
//   msg: string;
//   result: string;
// }

// 使用枚举
enum Api {
  // 分页查询仪器
  selectDevByPage = "/dev/selectByPage",
  // 添加仪器
  addDev = "/dev/add",
  // 修改仪器
  editDev = "/dev/edit",
  // 删除仪器
  deleteDev = "/dev/delete",
  // 查询所有仪器
  selectAllDev = "/dev/select",
  // 根据名称查询仪器
  selectDevByName = "/selectByName"
}

// 分页查询仪器的Api
export const selectDevByPageApi = (data: { devCode: string; devName: string; page: number; size: number }) => {
  return http.post<selectResType>(Api.selectDevByPage + joinQueryParams(data), {}, { loading: false });
};

// 添加仪器的Api
export const addDevApi = (data: {
  devCode: string;
  devName: string;
  devType: string;
  devUnit: string;
  devHome: string;
  devStatus: string | number;
  devStoreTime: string;
  devDesc: string;
}) => {
  return http.post(Api.addDev + joinQueryParams(data), {}, { loading: false });
};

// 修改仪器的Api
export const editDevApi = (data: {
  devId: number | string;
  devCode: string;
  devName: string;
  devType: string;
  devUnit: string;
  devHome: string;
  devStatus: string | number;
  devStoreTime: string;
  devDesc: string;
}) => {
  return http.post(Api.editDev + joinQueryParams(data), {}, { loading: false });
};

// 删除仪器的Api
export const deleteDevApi = data => {
  return http.post(Api.deleteDev + joinQueryParams(data), {}, { loading: false });
};

// 查询所有仪器的Api
export const selectAllDevApi = () => {
  return http.post(Api.selectAllDev, {}, { loading: false });
};

// 根据名称查询仪器的Api
export const selectDevByNameApi = (data: { devName: string }) => {
  return http.post(Api.selectDevByName + joinQueryParams(data), {}, { loading: false });
};
